package cn.chencq.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.chencq.demo.service.DemoService;
import cn.chencq.mq.ConsumerHandler;

import com.alibaba.fastjson.JSONObject;

public class DemoHandler implements ConsumerHandler {

	private static final Logger LOGGER = LoggerFactory.getLogger(DemoHandler.class);

	private String workName;

	public DemoHandler(String workName) {
		super();
		this.workName = workName;
	}

	@Override
	public boolean handler(String message) {
		try {
			LOGGER.info("{}-Handler 消费消息:{}", workName, message);

			JSONObject jsonObject = JSONObject.parseObject(message);

			String key = jsonObject.getString("keyword");
			// 业务处理
			DemoService.doSome(key);

			return true;
		} catch (Exception e) {
			LOGGER.error("{}-Handler 消费消息:{}", workName, message, e);
			e.printStackTrace();
			return false;
		}

	}

}
